import { mergeConfig } from 'vite';

import configArcoResolverPlugin from './plugin/arcoResolver';
import configCompressPlugin from './plugin/compress';
import configImageminPlugin from './plugin/imagemin';
import configVisualizerPlugin from './plugin/visualizer';
import baseConfig from './vite.config.base';

export default mergeConfig(
  {
    mode: 'production',
    plugins: [
      configArcoResolverPlugin(), // 配置 arco 组件按需引入
      configImageminPlugin(), // 启用图片压缩
      configCompressPlugin('gzip'), // 启用 gzip 压缩
      configVisualizerPlugin(), // 生成打包分析
    ],
    build: {
      rollupOptions: {
        output: {
          // 手动配置代码分割
          manualChunks: {
            arco: ['@arco-design/web-vue'],
            chart: ['echarts', 'vue-echarts'],
            vue: ['vue', 'vue-router', 'pinia', '@vueuse/core', 'vue-i18n'],
          },
        },
      },
      chunkSizeWarningLimit: 2000,
    },
  },
  baseConfig
);
